//
//  HRSegmentView.m
//  Hear
//
//  Created by mac on 2017/6/15.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRSegmentView.h"
#import "HRFMDBDynamicNotifacationTool.h"
@interface HRSegmentView ()
@property (nonatomic, strong)UIButton *tempButton;
@property (nonatomic, strong)UILabel *lineLabel;

@end
@implementation HRSegmentView

-(instancetype)initWithFrame:(CGRect)frame andTitleArray:(NSArray *)titleArray
{
    self = [super initWithFrame:frame];
    if (self)
    {
        CGFloat buttonWidth = frame.size.width/2;
        for (int i = 0;i < titleArray.count; i ++) {
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(i*buttonWidth, 0, buttonWidth, frame.size.height)];
            [button setTitle:titleArray[i] forState:UIControlStateNormal];
            button.tag = i;
            [self addSubview:button];
            button.titleLabel.font = CustomUIFont(14);
            if (i == 0){
                self.tempButton = button;
                [button setTitleColor:BlueColor forState:UIControlStateNormal];
                self.lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, button.bottom, button.width, 2)];
                self.lineLabel.backgroundColor = BlueColor;
                [self addSubview:self.lineLabel];
            }else{
                [button setTitleColor:FirstTextColor forState:UIControlStateNormal];
            }
            button.userInteractionEnabled = YES;
            [button addTarget:self action:@selector(cutClick:) forControlEvents:UIControlEventTouchUpInside];
            
            
            
        }
        
//        UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height-1, frame.size.width, 1)];
//        lineLabel.backgroundColor = CustomColor(200, 200, 200, 1);
//        [self addSubview:lineLabel];
    }
    return self;
}

- (void)cutClick:(UIButton *)button{
    [self.tempButton setTitleColor:FirstTextColor forState:UIControlStateNormal];
    self.tempButton = button;
    [button setTitleColor:BlueColor forState:UIControlStateNormal];
    if (self.cutTypeViewBlock){
        self.cutTypeViewBlock(button.tag);
    }
    WeakSelf
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.lineLabel.left = button.left;
    }];
}


@end
